package com.denlaku.longan.service.impl;

import com.denlaku.longan.anno.RequiredTx;
import com.denlaku.longan.repository.MeasureRepository;
import com.denlaku.longan.service.MeasureService;
import com.denlaku.longan.util.SnowflakeUtils;
import com.denlaku.longan.vo.Measure;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tianx
 */
@Service
public class MeasureServiceImpl implements MeasureService {
    @Autowired
    private MeasureRepository measureRepository;

    @Override
    @RequiredTx
    public void batchAdd(List<Measure> measureList) {
        if (CollectionUtils.isNotEmpty(measureList)) {
            measureList.forEach(measure -> measure.setId(SnowflakeUtils.nextId()));
            measureRepository.batchAdd(measureList);
        }
    }

    @Override
    @RequiredTx
    public void delete(Long tenantId, List<Long> componentIds) {
        measureRepository.delete(tenantId, componentIds);
    }

    @Override
    public List<Measure> list(Long tenantId, List<Long> componentIds) {
        return measureRepository.list(tenantId, componentIds);
    }

}
